<template>
	<u-popup v-model="show" mode="center" :mask-close-able="false" border-radius="20">
		<view class="popVue">
			<view class="title text-center">修改昵称</view>
			<input type="text" placeholder="请输入昵称" v-model="nick"/>
			<view class="flex-between margin50">
				<view class="cancel" @click="cancel()">取消</view>
				<view class="confirm" @click="confirm()">确认</view>
			</view>
		</view>
	</u-popup>
</template>

<script>
	export default {
		props: {
			show: {
				type: Boolean,
				default: false
			},
		},
		data(){
			return {
				nick: ""
			}
		},
		methods: {
			cancel(){
				this.nick = ""
				this.$emit("cancel")
			},
			async confirm(){
				if(!this.nick) return this.$u.toast("请输入昵称")
				const result = await this.$request("/app-api/member/user/update", "PUT", {
					nickname: this.nick,
				})
				if(result.code===0) {
					this.cancel()
					this.$u.toast("修改成功")
					this.nick = ""
					this.$store.dispatch("getUser")
				}else {
					this.$u.toast(result.msg)
				}
			}
		}
	}
</script>

<style lang="less" scoped>
	.popVue {
		width: 690rpx;
		padding: 30rpx 40rpx 50rpx;
		.title {
			color: #333;
			font-size: 32rpx;
			font-weight: 600;
		} 
		input {
			width: 100%;
			height: 88rpx;
			border: 1rpx solid #f5f5f5;
			display: block;
			box-sizing: border-box;
			border-radius: 12rpx;
			padding-left: 20rpx;
			color: #333;
			font-size: 28rpx;
			margin-top: 30rpx;
		}
		.cancel, .confirm {
			width: 280rpx;
			height: 82rpx;
			text-align: center;
			line-height: 82rpx;
			font-weight: 600;
			border-radius: 20rpx;
			font-size: 30rpx;
		}
		.cancel {
			border: 1rpx solid #1CC289;
			color: #1CC289;
		}
		.confirm {
			background: linear-gradient(to right, #1CC289, #60A5FA);
			color: #fff;
		}
	}
</style>